package com.study;

import com.study.limit.LimitByZset;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

/**
 * 通过zset实现简单限流
 * @Author ytj
 * @Date 2021/11/14 21:27
 */
@SpringBootTest
@RunWith(SpringRunner.class)
public class SimpleLimit {
    @Autowired
    private LimitByZset limitByZset;

    @Test
    public void test() throws Exception{
        for(int i=0;i<20;i++){
            boolean flg=this.limitByZset.limit("ytj","add",7,5);
            if(flg){
                System.out.println("操作成功:"+i);
            }else{
                System.out.println("超过限制次数");
            }
            //睡1S
            Thread.sleep(1000);
        }
    }




}
